<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/serverUrl.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>

		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">个人信息</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell">
					<a>账号<span id="zhanghao" class="mui-pull-right text"></span></a>
				</li>
				<li class="mui-table-view-cell">
					<a>姓名<span id="xingming" class="mui-pull-right text"></span></a>
				</li>
				<li class="mui-table-view-cell">
					<a>班级<span id="banji" class="mui-pull-right text"></span></a>
				</li>
				<li class="mui-table-view-cell">
					<a>手机<span id="shouji" class="mui-pull-right text"></span></a>
				</li>
			</ul>
			<br />
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" id="update">
					<a>检查更新<span class="mui-pull-right text"></span></a>
				</li>
				<li class="mui-table-view-cell" id="resetPassword">
					<a>修改密码<span class="mui-pull-right text"></span></a>
				</li>
				<li class="mui-table-view-cell" id="exitApp">
					<a style="color: red;">注销并退出<span class="mui-pull-right text"></span></a>
				</li>
			</ul>
		</div>
	</body>
	<script type="text/javascript">
		// 获取用户信息
		$.ajax({
			//请求方式
			type: "POST",
			dataType: "json",
			url: serverUrl + "getInformation",
			data: {
				account: localStorage.getItem("account"),
				password: localStorage.getItem("password")
			},
			//请求成功
			success: function(data) {
				document.getElementById("zhanghao").innerHTML = data.account;
				document.getElementById("xingming").innerHTML = data.name;
				document.getElementById("banji").innerHTML = data.className;
				document.getElementById("shouji").innerHTML = data.teleNumber;
				// 将userID保存到本地
				localStorage.setItem("userInformation", JSON.stringify(data));

			},
			//请求失败，包含具体的错误信息
			error: function(e) {
				mui.toast("遇到了未知错误！");
			}
		});

		//检查更新按钮点击事件
		document.getElementById("update").onclick = function() {
			mui.getJSON("manifest.json", null, function(data) {
				$.ajax({
					//请求方式
					type: "POST",
					dataType: "json",
					url: serverUrl + "checkVersion",
					data: {
						version: data.version.name
					},
					//请求成功
					success: function(data2) {
						if (data2.version == data.version.name) {
							mui.toast("您的版本已经是最新版本！");
						} else {
							mui.confirm(data2.description, '有新的版本', ["确认", "取消"],
								function(e) {
									if (e.index == 1) {} else {
										 mui.openWindow({
										    url: serverUrl + 'downloadApk', 
										  });
									}
								});

						}
					},
					//请求失败，包含具体的错误信息
					error: function(e) {
						mui.toast("遇到了未知错误！");
					}
				});
			})

		}

		//修改密码按钮点击事件
		document.getElementById("resetPassword").onclick = function() {
			mui.openWindow({
				url: "resetPassword.html",
				createNew: false, //不允许重复创建
				show: {
					autoShow: true,
					aniShow: "slide-in-right",
					duration: 100
				}
			});
		};

		// 注销按钮点击事件
		mui.plusReady(function() {
			document.getElementById("exitApp").onclick = function() {
				var btnArray = ['是', '否'];
				mui.confirm('注销', '确定', btnArray, function(e) {
					if (e.index == 1) {

					} else {
						localStorage.setItem("account", "");
						localStorage.setItem("password", "");
						plus.runtime.quit();
					}
				})
			}
		});
	</script>
</html>
